<!--描述模板列表-->
<template>
  <div class="app-container horizontal">
    <!-- 搜索查询 -->
    <div class="form-container">
      <el-form ref="queryForm" :inline="true" label-width="80px" :model="filters">
        <el-form-item label="静探编号" prop="explorationCode">
          <el-input
            v-model="filters.explorationCode"
            size="small"
            placeholder
            clearable
          />
        </el-form-item>
      </el-form>
    </div>
    <!--操作按钮-->
    <div class="btns-group">
      <el-button v-clickForbidden icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      <el-button v-clickForbidden icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      <el-button icon="el-icon-tickets" size="mini" :disabled="single" @click="staticExplorationReport()">静探报告</el-button>
      <span class="personal-type">
        <el-button icon="el-icon-arrow-left" size="mini" @click="handleReturn()">返回</el-button>
      </span>
    </div>
    <!-- 表格展示start -->
    <el-table
      ref="multipleTable"
      v-loading="loading"
      :data="tableData"
      :row-style="rowClass"
      style="width: 100%;"
      stripe
      class="table-list"
      :class="highLevelSet===true ? (needTagsView===true ? 'el-body-page-roll-tag-height' : 'el-body-page-roll-height') :
        (needTagsView===true ? 'el-body-page-roll-tag' : 'el-body-page-roll')"
      @selection-change="handleSelectionChange"
      @row-click="rowChecked"
    >
      <el-table-column type="selection" width="38" align="center" />
      <el-table-column type="index" label="序号" width="51" align="center" />
      <el-table-column
        prop="explorationCode"
        label="编号"
        min-width="160"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="explorationType"
        label="类型"
        min-width="120"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="{row}">
          <span v-if="row.explorationType === '0'">钻探</span>
          <span v-if="row.explorationType === '1'">静探</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="x"
        label="坐标经度"
        min-width="100"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="y"
        label="坐标纬度"
        min-width="100"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="elevation"
        label="高程"
        min-width="100"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="startTime"
        label="开孔时间"
        align="center"
        min-width="150"
      />
      <el-table-column
        prop="endTime"
        label="终孔时间"
        align="center"
        min-width="150"
      />
    </el-table>
    <!-- 分页-->
    <pagination
      :total="total"
      :page.sync="filters.pageNum"
      :limit.sync="filters.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
// 页面接口
import { listExploration } from '@/api/projectManage/project/exploration'
import { mapState } from 'vuex'
export default {
  data() {
    return {
      /* 搜索条件 start*/
      highLevelSet: false, // 高级设置显示隐藏
      filters: {
        // 查询参数
        pageNum: 1,
        pageSize: this.fristPageSize,
        drillHole: '1',
        explorationCode: ''
      },
      /* 搜索条件 end*/
      /* 列表 start*/
      total: 0, // 分页总条数
      single: true, // 非单个禁用
      selectRow: [], // 高亮样式
      multipleSelection: [], // 选中表格行
      loading: false, // 列表加载
      tableData: [] // 列表数据
      /* 列表 end*/
    }
  },
  computed: {
    ...mapState({
      needTagsView: (state) => state.settings.tagsView
    }),
    // 高级搜索显示隐藏
    handleTagShow() {
      return this.highLevelSet
    }
  },
  mounted() {
    // 获取列表
    this.getList()
  },
  methods: {
    // 返回
    handleReturn() {
      this.$router.go(-1)
    },
    staticExplorationReport() {
      const { id: explorationId, staticTestFile } = this.multipleSelection[0]
      const { proId } = this.$route.query
      this.$router.push({
        path: '/newProject/staticProbePoint-add',
        query: { explorationId, proId, staticTestFile }
      })
    },
    // 获取列表
    getList() {
      this.loading = true
      listExploration(this.filters).then(res => {
        this.loading = false
        if (res) {
          this.tableData = res.data.rows
          this.total = res.data.total
          // this.addTaleData()
        } else {
          this.msgError(res.message)
        }
      })
    },
    /* 列表 start*/
    // list表格填充空白行
    addTaleData() {
      if (this.tableData.length < this.fristPageSize) {
        const arr = {}
        this.tableData.push(arr)
        this.addTaleData()
      }
    },
    // 单击每行时每行的复选框选中
    rowChecked(row) {
      const selectData = this.multipleSelection
      this.$refs.multipleTable.clearSelection()
      if (selectData.length === 1) {
        selectData.forEach((item) => {
          // 判断 如果当前的一行被勾选, 再次点击的时候就会取消选中
          if (item === row) {
            this.$refs.multipleTable.toggleRowSelection(row, false)
          } else {
            this.$refs.multipleTable.toggleRowSelection(row, true)
          }
        })
      } else {
        this.$refs.multipleTable.toggleRowSelection(row, true)
      }
    },
    // 点击表格前面选框时触发的事件
    handleSelectionChange(val) {
      if (JSON.stringify(val[0]) === '{}') {
        this.$refs.multipleTable.clearSelection()
        val = []
      }
      if (val.length === 1) {
        this.single = false
      } else {
        this.single = true
      }
      this.selectRow = []
      this.multipleSelection = val
      if (this.multipleSelection.length > 0) {
        this.multipleSelection.forEach((item, index) => {
          this.selectRow.push(this.tableData.indexOf(item))
        })
      }
      if (val.length > 1) {
        this.$refs.multipleTable.clearSelection()
        this.$refs.multipleTable.toggleRowSelection(val.pop())
      }
    },
    // 高亮样式
    rowClass({ row, rowIndex }) {
      if (this.selectRow.includes(rowIndex)) {
        return { 'background-color': 'rgba(185,221,249,.75)' }
      }
    },
    /* 列表 end*/

    /* 按钮 start */
    // 搜索方法
    handleQuery() {
      this.filters.pageNum = 1
      this.getList()
    },
    // 重置搜索
    resetQuery() {
      this.resetForm('queryForm')
      this.dateRange = []
      this.handleQuery()
    }
    /* 列表 end */
  }
}
</script>

